﻿using Winista.Text.HtmlParser;
using Winista.Text.HtmlParser.Filters;
using Winista.Text.HtmlParser.Util;

namespace COC.Webs
{
    /// <summary>
    /// 部落数据解析工具类
    /// </summary>
    public class ClanDataParser
    {
        public static string Parse(string html, string troops)
        {
            string itemName = troops.ToLower().Replace("_","").Replace(".", "").Replace("baby", "").Replace("miner", "healer");
            var parser1 = Parser.CreateParser(html, "urf-8");  //utf-8
            NodeFilter filter1 = new AndFilter(new TagNameFilter("table"), new HasAttributeFilter("id",$"{itemName}-table-1"));
            NodeList nodeList1 = parser1.Parse(filter1);
            var table1 = nodeList1 != null ? nodeList1.ToHtml() : "";

            var parser2 = Parser.CreateParser(html, "urf-8");
            NodeFilter filter2 = new AndFilter(new TagNameFilter("table"), new HasAttributeFilter("id",$"{itemName}-table-2"));
            NodeList nodeList2 = parser2.Parse(filter2);
            var table2 =  nodeList2 != null ? nodeList2.ToHtml() : "";

            return $"{table1}<hr>{table2}";
        }
    }
}
